package value

import (
	"context"

	"tongquetai_server/activity_vk/infrastructure/utils"
)

/*
铜雀台道具定义
*/

type TqtItem struct {
	ItemId   string `json:"itemId"`
	ItemName string `json:"itemName"`
}

type TqtAward struct {
	TqtItem
	ItemCount int `json:"itemCount" validate:"gte=0"`
}

type TqtAwardWithWeight struct {
	TqtAward
	ItemWeight int `json:"itemWeight" validate:"gte=0"`
}

// TqtAwardWithWeightAndDisplay 道具名称*数量*权重*发光
type TqtAwardWithWeightAndDisplay struct {
	TqtAwardWithWeight
	DisplayTyp int `json:"displayTyp" validate:"gte=0"` // *发光/停留：填写内容限制数字：0,1,2
}

/*
服务端道具定义
*/

type SvrItem struct {
	GameObjectId string `json:"game_object_id,omitempty"`
}

type SvrAward struct {
	SvrItem
	Count int `json:"count,omitempty"`
}

type SvrAwardWithWeight struct {
	SvrAward
	WeightValue int `json:"weight_value"`
}

type SvrAwardWithWeightAndDisplay struct {
	SvrAwardWithWeight
	DisplayTyp int `json:"display_typ"`
}

/*
铜雀台 转 服务端
*/

func TqtToSvrItem(item TqtItem) SvrItem {
	return SvrItem{
		GameObjectId: item.ItemId,
	}
}

func TqtToSvrItems(items []TqtItem) []SvrItem {
	res := make([]SvrItem, len(items))
	for i, v := range items {
		res[i] = TqtToSvrItem(v)
	}

	return res
}

func TqtToSvrAward(item TqtAward) SvrAward {
	return SvrAward{
		SvrItem: TqtToSvrItem(item.TqtItem),
		Count:   item.ItemCount,
	}
}

func TqtToSvrAwards(items []TqtAward) []SvrAward {
	res := make([]SvrAward, len(items))
	for i, v := range items {
		res[i] = TqtToSvrAward(v)
	}

	return res
}

func TqtToSvrAwardWithWeight(item TqtAwardWithWeight) SvrAwardWithWeight {
	return SvrAwardWithWeight{
		SvrAward:    TqtToSvrAward(item.TqtAward),
		WeightValue: item.ItemWeight,
	}
}

func TqtToSvrAwardWithWeights(items []TqtAwardWithWeight) []SvrAwardWithWeight {
	res := make([]SvrAwardWithWeight, len(items))
	for i, v := range items {
		res[i] = TqtToSvrAwardWithWeight(v)
	}

	return res
}

func TqtToSvrAwardWithWeightAndDisplay(item TqtAwardWithWeightAndDisplay) SvrAwardWithWeightAndDisplay {
	return SvrAwardWithWeightAndDisplay{
		SvrAwardWithWeight: TqtToSvrAwardWithWeight(item.TqtAwardWithWeight),
		DisplayTyp:         item.DisplayTyp,
	}
}

func TqtToSvrAwardWithWeightAndDisplays(items []TqtAwardWithWeightAndDisplay) []SvrAwardWithWeightAndDisplay {
	res := make([]SvrAwardWithWeightAndDisplay, len(items))
	for i, v := range items {
		res[i] = TqtToSvrAwardWithWeightAndDisplay(v)
	}
	return res
}

/*
服务端 转 铜雀台
*/

func SvrToTqtItem(ctx context.Context, item SvrItem) TqtItem {
	return TqtItem{
		ItemId:   item.GameObjectId,
		ItemName: utils.GetItemNameByItemId(ctx, item.GameObjectId),
	}
}

func SvrToTqtItems(ctx context.Context, items []SvrItem) []TqtItem {
	res := make([]TqtItem, len(items))
	for i, v := range items {
		res[i] = SvrToTqtItem(ctx, v)
	}

	return res
}

func SvrToTqtAward(ctx context.Context, item SvrAward) TqtAward {
	return TqtAward{
		TqtItem:   SvrToTqtItem(ctx, item.SvrItem),
		ItemCount: item.Count,
	}
}

func SvrToTqtAwards(ctx context.Context, items []SvrAward) []TqtAward {
	res := make([]TqtAward, len(items))
	for i, v := range items {
		res[i] = SvrToTqtAward(ctx, v)
	}

	return res
}

func SvrToTqtAwardWithWeight(ctx context.Context, item SvrAwardWithWeight) TqtAwardWithWeight {
	return TqtAwardWithWeight{
		TqtAward:   SvrToTqtAward(ctx, item.SvrAward),
		ItemWeight: item.WeightValue,
	}
}

func SvrToTqtAwardWithWeights(ctx context.Context, items []SvrAwardWithWeight) []TqtAwardWithWeight {
	res := make([]TqtAwardWithWeight, len(items))
	for i, v := range items {
		res[i] = SvrToTqtAwardWithWeight(ctx, v)
	}

	return res
}

func SvrToTqtAwardWithWeightAndDisplay(ctx context.Context, item SvrAwardWithWeightAndDisplay) TqtAwardWithWeightAndDisplay {
	return TqtAwardWithWeightAndDisplay{
		TqtAwardWithWeight: SvrToTqtAwardWithWeight(ctx, item.SvrAwardWithWeight),
		DisplayTyp:         item.DisplayTyp,
	}
}

func SvrToTqtAwardWithWeightAndDisplays(ctx context.Context, items []SvrAwardWithWeightAndDisplay) []TqtAwardWithWeightAndDisplay {
	res := make([]TqtAwardWithWeightAndDisplay, len(items))
	for i, v := range items {
		res[i] = SvrToTqtAwardWithWeightAndDisplay(ctx, v)
	}
	return res
}
